#include <algorithm>
#include <cstdio>

constexpr int N = 2505;
constexpr double eps = 1e-5, inf = 1e9;

int n, k, s[N], p[N], siz[N];
double f[N][N], ns[N];
int e_cnt, heads[N];

inline void max(double &x, double y) {
  if (x < y) x = y;
}

struct Edge {
  int v, nxt;
} e[N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void solve(int x);

inline bool check(double mid) {
  for (register int i = 1; i <= n; ++i) ns[i] = p[i] - s[i] * mid;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) f[i][j] = -inf;
  solve(0);
  return f[0][k + 1] > 0;
}

void solve(int x) {
  f[x][1] = ns[x], f[x][0] = -inf, siz[x] = 1;
  for (register int i = heads[x], v; i; i = e[i].nxt) {
    solve(v = e[i].v);
    siz[x] += siz[v];
    for (int j = siz[x], lim = std::min(j, siz[v]); j; --j, lim = std::min(j, siz[v])) {
      for (register int h = 1; h <= lim; ++h) max(f[x][j], f[v][h] + f[x][j - h]);
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P4322 [JSOI2016]最佳团体.in", "r", stdin);
  freopen("P4322 [JSOI2016]最佳团体.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &k, &n);
  for (int i = 1, fa; i <= n; ++i) {
    scanf("%d%d%d", &s[i], &p[i], &fa);
    add(fa, i);
  }
  double l = 0, r = 1e5, mid;
  while (r - l > eps) {
    mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  printf("%.3lf", l);
  return 0;
}